<?php

namespace App\Job;

use App\Constants\FemaleKeepPushCode;
use App\Model\FemaleKeepPush;
use App\Model\InviteVideoLog;
use App\Model\Setting\SettingAppHidden;
use App\Model\User;
use App\Model\UserProfile;
use FemalePushGiftService;
use Hyperf\AsyncQueue\Job;

class FemaleKeepPushJob extends Job
{

    /**
     * 参数
     */
    public $params;

    /**
     * 任务执行失败后的重试次数，即最大执行次数为 $maxAttempts+1 次
     *
     * @var int
     */
    protected $maxAttempts = 1;
    /**
     * 构造函数
     * @param $params
     */
    public function __construct($params)
    {
        $this->params = $params;
    }

    /**
     *
     * @return void
     */
    public function handle()
    {
        $userId = $this->params['user_id'] ?? 0;
        if (!$userId || $userId == 0){
            return;
        }
        $pushNum = $this->params['push_num'] ?? 1;
        $batchNo = $this->params['batch_no'] ?? 1;

        log_info(__CLASS__ . "==".json_encode($this->params));
        //礼物
        $femalePushGiftService = new FemalePushGiftService();
        $ret = $femalePushGiftService->pushSysGift($userId, [
            'host_cate' => 0,
            'gift_id' => FemaleKeepPushCode::GIFT_ID,
            'gift_num' => env('USER_SYSGIFT_MAX_NUM', 50000),
            'single_gift_num' => $pushNum,
            'gift_expire_time' => FemaleKeepPushCode::GIFT_EXPIRATION_TIME,
        ]);
        $pushHostIds = $ret['push_uids'] ?? [];

        log_user_result($userId, "BatchNo:{$batchNo}==PushHosts:" . json_encode($pushHostIds));
        return;
    }
}